package com.meilele.dao.hongdian;

import com.meilele.entity.hongdian.ThiImages;
import com.meilele.entity.hongdian.ThiShow;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface ThiShowMapper {
    @Delete({
        "delete from thi_show",
        "where show_id = #{showId,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer showId);

    @Insert({
        "insert into thi_show (show_id, show_image, ",
        "show_company, show_desc, ",
        "show_style, show_city, ",
        "show_room, show_area, ",
        "show_price, show_logo, ",
        "show_num, server_area, ",
        "show_comment)",
        "values (#{showId,jdbcType=INTEGER}, #{showImage,jdbcType=VARCHAR}, ",
        "#{showCompany,jdbcType=VARCHAR}, #{showDesc,jdbcType=VARCHAR}, ",
        "#{showStyle,jdbcType=VARCHAR}, #{showCity,jdbcType=VARCHAR}, ",
        "#{showRoom,jdbcType=VARCHAR}, #{showArea,jdbcType=INTEGER}, ",
        "#{showPrice,jdbcType=VARCHAR}, #{showLogo,jdbcType=VARCHAR}, ",
        "#{showNum,jdbcType=INTEGER}, #{serverArea,jdbcType=VARCHAR}, ",
        "#{showComment,jdbcType=LONGVARCHAR})"
    })
    int insert(ThiShow record);

    int insertSelective(ThiShow record);

    @Select({
        "select",
        "show_id, show_image, show_company, show_desc, show_style, show_city, show_room, ",
        "show_area, show_price, show_logo, show_num, server_area, show_comment",
        "from thi_show",
        "where show_id = #{showId,jdbcType=INTEGER}"
    })
    @ResultMap("com.meilele.dao.hongdian.ThiShowMapper.ResultMapWithBLOBs")
    ThiShow selectByPrimaryKey(Integer showId);


    /**
     * 点击图片,根据id进入详情界面
     */
    @Results(value = {
            @Result(column="show_id" , property="showId"),
            @Result(column="show_image" , property="showImage"),
            @Result(column="show_company" , property="showCompany"),
            @Result(column="show_desc" , property="showDesc"),
            @Result(column="show_style" , property="showStyle"),
            @Result(column="show_city" , property="showCity"),
            @Result(column="show_room" , property="showRoom"),
            @Result(column="show_area" , property="showArea"),
            @Result(column="show_price" , property="showPrice"),
            @Result(column="show_comment" , property="showComment"),
            @Result(column="show_logo" , property="showLogo"),
            @Result(column="show_num" , property="showNum"),
            @Result(column="server_area" , property="serverArea") ,
            @Result(column = "show_id" , property = "imagesList",
                    javaType = List.class ,
                    many = @Many(select = "com.meilele.dao.hongdian.ThiShowMapper.findDetailsById"))
    })
    @Select("SELECT show_id, show_image, show_company, show_desc, show_style, show_city, show_room, show_area, show_price, show_comment, show_logo, show_num, server_area FROM thi_show \n" +
            "WHERE show_id = #{showId}")
    ThiShow findAllDetails(int showId);

    /**
     * 查询详情的同时，获取它所有的图片信息
     * @param showId
     */
    @Results(value = {
            @Result(column="image_id" , property="imageId"),
            @Result(column="image_img" , property="imageImg"),
            @Result(column="image_desc" , property="imageDesc"),
            @Result(column="show_id" , property="showId")
    })
    @Select({"SELECT i.image_id, i.image_img,i.image_name, i.image_desc FROM thi_show s\n" +
            "INNER JOIN thi_images i \n" +
            "ON i.show_id = s.show_id\n" +
            "WHERE s.show_id = #{showId}"})
    List<ThiImages> findDetailsById(int showId);







    int updateByPrimaryKeySelective(ThiShow record);

    @Update({
        "update thi_show",
        "set show_image = #{showImage,jdbcType=VARCHAR},",
          "show_company = #{showCompany,jdbcType=VARCHAR},",
          "show_desc = #{showDesc,jdbcType=VARCHAR},",
          "show_style = #{showStyle,jdbcType=VARCHAR},",
          "show_city = #{showCity,jdbcType=VARCHAR},",
          "show_room = #{showRoom,jdbcType=VARCHAR},",
          "show_area = #{showArea,jdbcType=INTEGER},",
          "show_price = #{showPrice,jdbcType=VARCHAR},",
          "show_logo = #{showLogo,jdbcType=VARCHAR},",
          "show_num = #{showNum,jdbcType=INTEGER},",
          "server_area = #{serverArea,jdbcType=VARCHAR},",
          "show_comment = #{showComment,jdbcType=LONGVARCHAR}",
        "where show_id = #{showId,jdbcType=INTEGER}"
    })
    int updateByPrimaryKeyWithBLOBs(ThiShow record);

    @Update({
        "update thi_show",
        "set show_image = #{showImage,jdbcType=VARCHAR},",
          "show_company = #{showCompany,jdbcType=VARCHAR},",
          "show_desc = #{showDesc,jdbcType=VARCHAR},",
          "show_style = #{showStyle,jdbcType=VARCHAR},",
          "show_city = #{showCity,jdbcType=VARCHAR},",
          "show_room = #{showRoom,jdbcType=VARCHAR},",
          "show_area = #{showArea,jdbcType=INTEGER},",
          "show_price = #{showPrice,jdbcType=VARCHAR},",
          "show_logo = #{showLogo,jdbcType=VARCHAR},",
          "show_num = #{showNum,jdbcType=INTEGER},",
          "server_area = #{serverArea,jdbcType=VARCHAR}",
        "where show_id = #{showId,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(ThiShow record);


    /**
     * 根据id查询展示案例对象
     * @param showId
     * @return
     */
    @Results(value = {
            @Result(column="show_id" , property="showId"),
            @Result(column="show_image" , property="showImage"),
            @Result(column="show_company" , property="showCompany"),
            @Result(column="show_desc" , property="showDesc"),
            @Result(column="show_style" , property="showStyle"),
            @Result(column="show_city" , property="showCity"),
            @Result(column="show_room" , property="showRoom"),
            @Result(column="show_area" , property="showArea"),
            @Result(column="show_price" , property="showPrice"),
            @Result(column="show_comment" , property="showComment"),
            @Result(column="show_logo" , property="showLogo"),
            @Result(column="show_num" , property="showNum"),
            @Result(column="server_area" , property="serverArea")
    })
    @Select("SELECT show_id, show_image, show_company, show_desc, show_style, show_city, show_room, show_area, show_price, show_comment, show_logo, show_num, server_area " +
            "FROM thi_show WHERE show_id = #{showId}")
    ThiShow findShowById(int showId);

    @Delete("DELETE FROM thi_show WHERE show_id = #{showId}")
    int deleteShow(int showId);

    @Update("UPDATE thi_show SET \n" +
            "show_id = #{showId}, show_image = #{showImage}, show_company = #{showCompany}, \n" +
            "show_desc = #{showDesc}, show_style = #{showStyle}, show_city = #{showCity},\n" +
            "show_room = #{showRoom}, show_area = #{showArea}, show_price = #{showPrice}, \n" +
            "show_comment = #{showComment}, show_logo = #{showLogo}, show_num = #{showNum}, \n" +
            "server_area = #{serverArea} WHERE show_id = #{showId}")
    int updateShow(ThiShow thiShow);
}